package com.example.mall.controller.v1;

import com.example.mall.common.core.response.SuccessResponse;
import com.example.mall.common.utils.GeneriAndJson;
import com.example.mall.common.utils.JwtToken;
import com.example.mall.common.utils.SuccessHelper;
import com.example.mall.dto.token.TokenVerifyDTO;
import com.example.mall.dto.user.UserSignInDTO;
import com.example.mall.dto.user.UserSignUpDTO;
import com.example.mall.dto.user.UserUpdateDTO;
import com.example.mall.entity.User;
import com.example.mall.service.PwdAuthenticationService;
import com.example.mall.service.UserService;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private PwdAuthenticationService pwdAuthenticationService;
    @Autowired
    private UserService userService;

    @PostMapping("/verify")
    public SuccessResponse verifyToken(@RequestBody TokenVerifyDTO tokenVerifyDTO) {
        boolean effectived = JwtToken.checkToken(tokenVerifyDTO.getToken());
        return SuccessHelper.excute("check", effectived);
    }

    /**
     * 用户注册账号密码
     * @param userSignUpDTO
     * @return
     */
    @PostMapping("/signup")
    public SuccessResponse register(@RequestBody @Validated UserSignUpDTO userSignUpDTO) {
        String token = pwdAuthenticationService.register(userSignUpDTO);
        return SuccessHelper.excute("token", token);
    }

    /**
     * 更新自己的基本信息
     * @param userUpdateDTO
     * @return
     */
    @PostMapping("/update")
    public SuccessResponse update(@RequestBody UserUpdateDTO userUpdateDTO) {

        return null;
    }

    /**
     * 更换头像
     * @return
     */
    @PostMapping("/upload")
    public SuccessResponse uploadAvatar (){
        return null;
    }
}
